using System;
using System.Collections.Generic;
using System.Text;
using Csla.Data;
using Csla;
using Active.Core.State;

namespace Active.Core
{
    /// <summary>
    /// The read only order infomation.
    /// </summary>
    [Serializable()]
    public class OrderInfo : ReadOnlyBase<OrderInfo>
    {
        #region Business Methods

        // TODO: add your own fields, properties and methods
        private int _id;
        /// <summary>
        /// Gets the id.
        /// </summary>
        /// <value>The id.</value>
        public int Id
        {
            get { return _id; }
        }

        private int _billId;
        public int BillId
        {
            get { return _billId; }
        }

        private string _number;
        public string Number
        {
            get { return _number; }
        }

        private string _playVersions = string.Empty;
        public string[] PlayVersions
        {
            get
            {
                if (string.IsNullOrEmpty(_playVersions))
                {
                    return null;
                }
                return _playVersions.Split('|');
            }
        }

        private int _mediaId;
        public int MediaId
        {
            get { return _mediaId; }
        }

        private string _mediaName = string.Empty;
        public string MediaName
        {
            get { return _mediaName; }
        }

        private DateTime _startDate;
        public DateTime StartDate
        {
            get { return _startDate; }
        }

        private SmartDate _endDate;
        public SmartDate EndDate
        {
            get { return _endDate; }
        }

        private StateValue _stateValue;
        public StateValue StateValue
        {
            get { return _stateValue; }
        }

        protected override object GetIdValue()
        {
            return _id;
        }

        #endregion

        #region Factory Methods

        internal static OrderInfo GetOrderInfo(SafeDataReader dr)
        {
            return new OrderInfo(dr);
        }

        private OrderInfo(SafeDataReader dr)
        {
            Fetch(dr);
        }

        #endregion

        #region Data Access

        private void Fetch(SafeDataReader dr)
        {
            _id = dr.GetInt32("Id");
            _billId = dr.GetInt32("BillId");
            _endDate = dr.GetSmartDate("EndDate", false);
            _mediaId = dr.GetInt32("MediaId");
            _mediaName = dr.GetString("Name");
            _playVersions = dr.GetString("PlayVersions");
            _startDate = dr.GetDateTime("StartDate");
            _stateValue = (StateValue)dr.GetInt32("StateValue");
            _number = dr.GetString("Number");
        }

        #endregion
    }
}
